package com.party.orders.dto;

import java.text.NumberFormat;

import com.party.domain.ShopCart;

/**
 * 
 * @author Caizhf
 * @date 2017年8月14日上午1:37:23
 * @version v.0.1
 * @email 1115054416@qq.com 
 *
 * <p>Description: 单类商品中的某个商品；计算清单中转对象</p>
 *
 */
public class ShopCartAmountDTO{
	private ShopCart shopCart;	//实际订单
	private double actualPay;	//该订单实际付款金额（减去优惠券按的百分比）
	private double productPrice;//该订单下的商品价格
	private double productPercentage;	//该产品价格占该类产品总额的百分比
	private double allPercentage;		//该产品价格占总共价格的百分比
	
	public ShopCartAmountDTO() {
		super();
		// TODO Auto-generated constructor stub
	}

	public ShopCartAmountDTO(ShopCart shopCart, double productPrice) {
		super();
		this.shopCart = shopCart;
		this.productPrice = productPrice;
	}

	/**
	 * 计算该产品优惠后的价格
	 * @param thisProducTotalPrice			该类产品的原总价
	 * @param thisProductTotalActualPay		该类产品优惠后的总价
	 * @return
	 */
	public double doActualPay(double thisProducTotalPrice,double thisProductTotalActualPay){
		//根据传入的总价算出该订单所占百分比
		NumberFormat numberFormat = NumberFormat.getInstance();
		numberFormat.setMaximumFractionDigits(6);
		if(thisProducTotalPrice!=0)
			productPercentage = Double.parseDouble(numberFormat.format(productPrice/thisProducTotalPrice));
		//根据百分比算出该订单需要的实际付款
		actualPay = thisProductTotalActualPay * productPercentage;
		return actualPay;
	}
	
	/**
	 * 计算该产品优惠后的价格
	 * @param allProductTotalAmount			所有产品的总价
	 * @param allProductTotalActualPay		所有产品的优惠后的总价
	 * @return
	 */
	public double doActualPayByAll(double allProductTotalAmount,double allProductTotalActualPay){
		//根据传入的总价算出该订单所占百分比
		NumberFormat numberFormat = NumberFormat.getInstance();
		numberFormat.setMaximumFractionDigits(6);
		if(allProductTotalAmount!=0)
			allPercentage = Double.parseDouble(numberFormat.format(productPrice/allProductTotalAmount));
		actualPay = allPercentage * allProductTotalActualPay;
		return actualPay;
	}
	
	
	public double getAllPercentage() {
		return allPercentage;
	}

	public void setAllPercentage(double allPercentage) {
		this.allPercentage = allPercentage;
	}

	public double getProductPercentage() {
		return productPercentage;
	}
	
	public void setProductPercentage(double productPercentage) {
		this.productPercentage = productPercentage;
	}
	
	public double getProductPrice() {
		return productPrice;
	}
	public void setProductPrice(double productPrice) {
		this.productPrice = productPrice;
	}
	public ShopCart getShopCart() {
		return shopCart;
	}
	public void setShopCart(ShopCart shopCart) {
		this.shopCart = shopCart;
	}
	public double getActualPay() {
		return actualPay;
	}
	public void setActualPay(double actualPay) {
		this.actualPay = actualPay;
	}

	@Override
	public String toString() {
		return "ShopCartAmountDTO [shopCart=" + shopCart + ", actualPay=" + actualPay + ", productPrice=" + productPrice
				+ ", productPercentage=" + productPercentage + "]";
	}
	
	
}
